<?php ?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style>
#iFrameID {
    opacity:1;
	background-color: transparent;
	position:absolute;
	width:100%;								
	height:100%;									
	top:0px;
	left:0px;
	margin-left: 0%;
  	margin-top: 0%;
	z-index:100;
	display: none;
	border-width: 0px;
}
</style>
</head>

<body oncontextmenu="return false;">
<iframe id="iFrameID" src="about:blank" allow="camera"></iframe>
<script type="text/javascript">

    onTryonClick();

function onTryonClick(argument) {
		
	let hostURL = window.location.href;
   	const urlParams = hostURL.split('?')[1];

	var url = "https://cdn.camweara.com/camweara_virtual_tryon/?" + urlParams;
 
	var iframe = document.getElementById("iFrameID");
	iframe.style.display = "block";
	iframe.setAttribute("src", url); 
}

window.addEventListener('message', function(event) { 

    if(event.data == "closeIframe" || typeof event.data == "string" && event.data.includes("buynow")){
    	console.log("closeIframe entered");
	    document.getElementById("iFrameID").setAttribute("src", ""); 
		document.getElementById("iFrameID").style.display = "none";
		window.close('', '_parent', '');
		window.history.back();

    }

}); 

</script>

</body>
</html>
